package com.zjb.demo.system.mapper;

import com.mybatisflex.core.BaseMapper;
import com.mybatisflex.core.query.QueryChain;
import com.zjb.demo.system.domain.SysPost;
import org.apache.ibatis.annotations.Mapper;

import java.util.List;

import static com.zjb.demo.system.domain.table.SysPostTableDef.SYS_POST;
import static com.zjb.demo.system.domain.table.SysUserPostTableDef.SYS_USER_POST;
import static com.zjb.demo.system.domain.table.UserTableDef.USER;

/**
 * @author 庄佳彬
 * @since 2023/12/30 22:47
 */
@Mapper
public interface SysPostMapper extends BaseMapper<SysPost> {
    /**
     * 选择用户所属职位组的信息
     *
     * @param username 用户名
     * @return 用户职位组的列表
     */
    default List<SysPost> selectUserPostGroup(String username) {
        return QueryChain.of(this)
                .select(SYS_POST.POST_ID, SYS_POST.POST_NAME, SYS_POST.POST_CODE)
                .from(SYS_POST)
                .leftJoin(SYS_USER_POST)
                .on(SYS_POST.POST_ID.eq(SYS_USER_POST.POST_ID))
                .leftJoin(USER)
                .on(SYS_USER_POST.USER_ID.eq(USER.ID))
                .where(USER.USER_NAME.eq(username))
                .list();
    }

}
